package com.example.fruitpool;

import java.util.ArrayList;
import java.util.Random;

import org.andengine.engine.camera.Camera;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.util.GLState;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.adt.pool.GenericPool;

import com.example.manager.ResourcesManager;

import android.util.Log;

public class BoomPool {

	private static BoomPool INSTANCE = new BoomPool();
	public static ResourcesManager resourcesManager;
	public static VertexBufferObjectManager vbom;

	Random ran = new Random();
	
	public static void prepareManager(ResourcesManager presourcesManager, VertexBufferObjectManager pvbom) 
	{
		resourcesManager = presourcesManager;
		vbom = pvbom;		
	}    
	public static BoomPool sharedBoomPool()
	{
		return INSTANCE;
	} 
	private BoomPool() {
		super();
	}

	public Boom onAllocatePoolItem() {
		
		int i = ran.nextInt(resourcesManager.mArrBoom.size());
		Sprite s;
		s = new Sprite(0, 0, resourcesManager.mArrBoom.get(i), vbom) {
			@Override
			protected void preDraw(final GLState pGLState, final Camera pCamera) {
				super.preDraw(pGLState, pCamera);
				pGLState.enableDither();
			}
		};
		// Sprite s = new Sprite(0, 0, ball, vbom);
		return new Boom(s, resourcesManager.mArrBoomId.get(i));
		
		}

	public void onHandleRecycleItem(final Boom e) {
		e.sprit.clearEntityModifiers();
		e.sprit.clearUpdateHandlers();
		e.sprit.setVisible(false);	
		e.sprit.detachSelf();
		e.sprit.reset();
	}
}